package com.SB.controller;

import com.SB.Result.Result;
import com.SB.Utils.StringUtil;
import com.SB.pojo.User;
import com.SB.server.LoginServer;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/xxx_xxx")
@Api(tags = "用户登陆")
public class LoginController {

    @Autowired
    private LoginServer loginServerimpl;

    @RequestMapping(value = "/login",method = {RequestMethod.GET,RequestMethod.POST})
   public String login(@RequestBody User user ,@RequestBody Map<String,String> map){
        String username = user.getUsername();
        String password = user.getPassword();
        String code = map.get("code");
        //判空
        if (StringUtil.isEmpty(code)){
            return " 验证码不能为空 ";
        }
        if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)){
            return " 用户名或密码错误 ";
        }
        //鉴权
//        if (){
//
//        }
        //判断验证码and用户名and密码是否正确
        List<User> UR = loginServerimpl.queryuser(username,password);
        for (User user1 : UR) {
            return user1.getName();
        }
        return null;
    }

}
